import CustomImgType from '@/platform/types/custom-img-type';
import React from 'react';
import PropTypes from 'prop-types';

const CustomImg:React.FC<CustomImgType> = (props) => {
    const imgError = (evn:any) => {
        const img = evn.srcElement ? evn.srcElement : evn.target
        
        if (props.errSrc !== '') {
            img.src = props.errSrc;
        }
    }
    return (
        <img
            src={props.imgSrc}
            className={props.imgClassName?.join(' ')}
            style={props.imgStyle} 
            onError={imgError}
            alt={props.imgAlt}
        />
    );
};

CustomImg.defaultProps = {
    errSrc: '',
    imgSrc: '',
    imgClassName: [],
    imgStyle: {},
    imgAlt: ''
}

CustomImg.propTypes = {
    errSrc: PropTypes.string,
    imgSrc: PropTypes.string,
    imgClassName: PropTypes.array,
    imgStyle: PropTypes.object,
    imgAlt: PropTypes.string
}

export default CustomImg;
